package com.iotmonitor.iot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.iotmonitor.iot.domain.TbGps;
import com.iotmonitor.iot.domain.dto.DeviceFullInfo;
import com.iotmonitor.iot.service.ITbGpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iotmonitor.common.log.annotation.Log;
import com.iotmonitor.common.log.enums.BusinessType;
import com.iotmonitor.common.security.annotation.RequiresPermissions;
import com.iotmonitor.common.core.web.controller.BaseController;
import com.iotmonitor.common.core.web.domain.AjaxResult;
import com.iotmonitor.common.core.utils.poi.ExcelUtil;
import com.iotmonitor.common.core.web.page.TableDataInfo;

/**
 * GPS配置Controller
 * 
 * @author ruoyi
 * @date 2023-08-11
 */
@RestController
@RequestMapping("/gps")
public class TbGpsController extends BaseController
{
    @Autowired
    private ITbGpsService tbGpsService;

    /**
     * 查询GPS配置列表
     */
    @RequiresPermissions("system:gps:list")
    @GetMapping("/list")
    public TableDataInfo list(TbGps tbGps)
    {
        startPage();
        List<TbGps> list = tbGpsService.selectTbGpsList(tbGps);
        return getDataTable(list);
    }

    /**
     * 导出GPS配置列表
     */
    @RequiresPermissions("system:gps:export")
    @Log(title = "GPS配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGps tbGps)
    {
        List<TbGps> list = tbGpsService.selectTbGpsList(tbGps);
        ExcelUtil<TbGps> util = new ExcelUtil<TbGps>(TbGps.class);
        util.exportExcel(response, list, "GPS配置数据");
    }

    /**
     * 获取GPS配置详细信息
     */
    @RequiresPermissions("system:gps:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbGpsService.selectTbGpsById(id));
    }

    /**
     * 新增GPS配置
     */
    @RequiresPermissions("system:gps:add")
    @Log(title = "GPS配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGps tbGps)
    {
        return toAjax(tbGpsService.insertTbGps(tbGps));
    }

    /**
     * 修改GPS配置
     */
    @RequiresPermissions("system:gps:edit")
    @Log(title = "GPS配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGps tbGps)
    {
        return toAjax(tbGpsService.updateTbGps(tbGps));
    }

    /**
     * 删除GPS配置
     */
    @RequiresPermissions("system:gps:remove")
    @Log(title = "GPS配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbGpsService.deleteTbGpsByIds(ids));
    }


    /**
     * 获取gps指标
     * @return
     */
    @GetMapping
    public TbGps get(){
        return tbGpsService.getGps();
    }

    /**
     * 根据经纬度获取设备信息
     * @param lat
     * @param lon
     * @param distance
     * @return
     */
    @GetMapping("/deviceList/{lat}/{lon}/{distance}")
    public List<DeviceFullInfo> getDeviceFullInfo(@PathVariable Double lat, @PathVariable Double lon, @PathVariable Integer distance  ){

        return tbGpsService.getDeviceFullInfo( lat,lon,distance );
    }
}
